package cn.maihe.elg.operation.exception;

/**
 * @Description
 * @Author WJH
 * @Date 2021/10/27
 */
public class ExceptionUtils {


    public static <E> E isAssignableFrom(Class<E> subClass, Throwable t) {
        if (subClass.isAssignableFrom(t.getClass())) {
            return (E) t;
        } else if (t.getCause() == null) {
            // 不存在指定的异常类则返回null
            return null;
        } else {
            return isAssignableFrom(subClass, t.getCause());
        }
    }
}
